package com.kexio.sms.config;

import org.springframework.boot.context.properties.ConfigurationProperties;

/**
 * 短信服务配置属性
 * 
 * @author Kexio Team
 * @since 1.0.0
 */
@ConfigurationProperties(prefix = "kexio.sms")
public class SmsProperties {
    
    /**
     * 是否启用短信服务
     */
    private boolean enabled = false;
    
    /**
     * 默认服务提供商
     */
    private String defaultProvider = "aliyun";
    
    /**
     * 备用服务提供商
     */
    private String fallbackProvider = "tencent";
    
    /**
     * 启用自动故障转移
     */
    private boolean enableFailover = true;
    
    /**
     * 阿里云配置
     */
    private AliyunConfig aliyun = new AliyunConfig();
    
    /**
     * 腾讯云配置
     */
    private TencentConfig tencent = new TencentConfig();
    
    /**
     * 华为云配置
     */
    private HuaweiConfig huawei = new HuaweiConfig();
    
    /**
     * 验证码配置
     */
    private VerificationConfig verification = new VerificationConfig();
    
    /**
     * 限流配置
     */
    private RateLimitConfig rateLimit = new RateLimitConfig();
    
    /**
     * 模板配置
     */
    private TemplateConfig template = new TemplateConfig();
    
    /**
     * 记录配置
     */
    private RecordConfig record = new RecordConfig();
    
    public static class AliyunConfig {
        private String accessKeyId;
        private String accessKeySecret;
        private String regionId = "cn-hangzhou";
        private String signName;
        private String endpoint = "dysmsapi.aliyuncs.com";
        
        // Getters and Setters
        public String getAccessKeyId() { return accessKeyId; }
        public void setAccessKeyId(String accessKeyId) { this.accessKeyId = accessKeyId; }
        
        public String getAccessKeySecret() { return accessKeySecret; }
        public void setAccessKeySecret(String accessKeySecret) { this.accessKeySecret = accessKeySecret; }
        
        public String getRegionId() { return regionId; }
        public void setRegionId(String regionId) { this.regionId = regionId; }
        
        public String getSignName() { return signName; }
        public void setSignName(String signName) { this.signName = signName; }
        
        public String getEndpoint() { return endpoint; }
        public void setEndpoint(String endpoint) { this.endpoint = endpoint; }
    }
    
    public static class TencentConfig {
        private String secretId;
        private String secretKey;
        private String region = "ap-guangzhou";
        private String appId;
        private String signName;
        private String endpoint = "sms.tencentcloudapi.com";
        
        // Getters and Setters
        public String getSecretId() { return secretId; }
        public void setSecretId(String secretId) { this.secretId = secretId; }
        
        public String getSecretKey() { return secretKey; }
        public void setSecretKey(String secretKey) { this.secretKey = secretKey; }
        
        public String getRegion() { return region; }
        public void setRegion(String region) { this.region = region; }
        
        public String getAppId() { return appId; }
        public void setAppId(String appId) { this.appId = appId; }
        
        public String getSignName() { return signName; }
        public void setSignName(String signName) { this.signName = signName; }
        
        public String getEndpoint() { return endpoint; }
        public void setEndpoint(String endpoint) { this.endpoint = endpoint; }
    }
    
    public static class HuaweiConfig {
        private String accessKey;
        private String secretKey;
        private String region = "cn-north-4";
        private String appId;
        private String signName;
        private String endpoint = "https://smsapi.cn-north-4.myhuaweicloud.com:443";
        
        // Getters and Setters
        public String getAccessKey() { return accessKey; }
        public void setAccessKey(String accessKey) { this.accessKey = accessKey; }
        
        public String getSecretKey() { return secretKey; }
        public void setSecretKey(String secretKey) { this.secretKey = secretKey; }
        
        public String getRegion() { return region; }
        public void setRegion(String region) { this.region = region; }
        
        public String getAppId() { return appId; }
        public void setAppId(String appId) { this.appId = appId; }
        
        public String getSignName() { return signName; }
        public void setSignName(String signName) { this.signName = signName; }
        
        public String getEndpoint() { return endpoint; }
        public void setEndpoint(String endpoint) { this.endpoint = endpoint; }
    }
    
    public static class VerificationConfig {
        /**
         * 默认验证码长度
         */
        private int defaultLength = 6;
        
        /**
         * 默认有效期 (分钟)
         */
        private int defaultExpireMinutes = 5;
        
        /**
         * 最大验证次数
         */
        private int maxVerifyCount = 3;
        
        /**
         * 是否使用数字验证码
         */
        private boolean useNumericCode = true;
        
        /**
         * 是否使用字母验证码
         */
        private boolean useAlphabeticCode = false;
        
        /**
         * 验证码模板
         */
        private String template = "您的验证码是：{code}，{expire}分钟内有效。";
        
        // Getters and Setters
        public int getDefaultLength() { return defaultLength; }
        public void setDefaultLength(int defaultLength) { this.defaultLength = defaultLength; }
        
        public int getDefaultExpireMinutes() { return defaultExpireMinutes; }
        public void setDefaultExpireMinutes(int defaultExpireMinutes) { this.defaultExpireMinutes = defaultExpireMinutes; }
        
        public int getMaxVerifyCount() { return maxVerifyCount; }
        public void setMaxVerifyCount(int maxVerifyCount) { this.maxVerifyCount = maxVerifyCount; }
        
        public boolean isUseNumericCode() { return useNumericCode; }
        public void setUseNumericCode(boolean useNumericCode) { this.useNumericCode = useNumericCode; }
        
        public boolean isUseAlphabeticCode() { return useAlphabeticCode; }
        public void setUseAlphabeticCode(boolean useAlphabeticCode) { this.useAlphabeticCode = useAlphabeticCode; }
        
        public String getTemplate() { return template; }
        public void setTemplate(String template) { this.template = template; }
    }
    
    public static class RateLimitConfig {
        /**
         * 是否启用限流
         */
        private boolean enabled = true;
        
        /**
         * 每天每个手机号最大发送次数
         */
        private int maxSendPerDayPerPhone = 10;
        
        /**
         * 每小时每个手机号最大发送次数
         */
        private int maxSendPerHourPerPhone = 5;
        
        /**
         * 发送间隔 (秒)
         */
        private int sendIntervalSeconds = 60;
        
        /**
         * 每天每个IP最大发送次数
         */
        private int maxSendPerDayPerIp = 100;
        
        // Getters and Setters
        public boolean isEnabled() { return enabled; }
        public void setEnabled(boolean enabled) { this.enabled = enabled; }
        
        public int getMaxSendPerDayPerPhone() { return maxSendPerDayPerPhone; }
        public void setMaxSendPerDayPerPhone(int maxSendPerDayPerPhone) { this.maxSendPerDayPerPhone = maxSendPerDayPerPhone; }
        
        public int getMaxSendPerHourPerPhone() { return maxSendPerHourPerPhone; }
        public void setMaxSendPerHourPerPhone(int maxSendPerHourPerPhone) { this.maxSendPerHourPerPhone = maxSendPerHourPerPhone; }
        
        public int getSendIntervalSeconds() { return sendIntervalSeconds; }
        public void setSendIntervalSeconds(int sendIntervalSeconds) { this.sendIntervalSeconds = sendIntervalSeconds; }
        
        public int getMaxSendPerDayPerIp() { return maxSendPerDayPerIp; }
        public void setMaxSendPerDayPerIp(int maxSendPerDayPerIp) { this.maxSendPerDayPerIp = maxSendPerDayPerIp; }
    }
    
    public static class TemplateConfig {
        /**
         * 是否启用模板缓存
         */
        private boolean enableCache = true;
        
        /**
         * 缓存过期时间 (分钟)
         */
        private int cacheExpireMinutes = 30;
        
        /**
         * 是否启用模板参数验证
         */
        private boolean enableParamValidation = true;
        
        // Getters and Setters
        public boolean isEnableCache() { return enableCache; }
        public void setEnableCache(boolean enableCache) { this.enableCache = enableCache; }
        
        public int getCacheExpireMinutes() { return cacheExpireMinutes; }
        public void setCacheExpireMinutes(int cacheExpireMinutes) { this.cacheExpireMinutes = cacheExpireMinutes; }
        
        public boolean isEnableParamValidation() { return enableParamValidation; }
        public void setEnableParamValidation(boolean enableParamValidation) { this.enableParamValidation = enableParamValidation; }
    }
    
    public static class RecordConfig {
        /**
         * 是否启用发送记录
         */
        private boolean enabled = true;
        
        /**
         * 记录保留天数
         */
        private int retentionDays = 30;
        
        /**
         * 是否记录失败日志
         */
        private boolean logFailures = true;
        
        /**
         * 是否自动清理过期记录
         */
        private boolean autoCleanup = true;
        
        // Getters and Setters
        public boolean isEnabled() { return enabled; }
        public void setEnabled(boolean enabled) { this.enabled = enabled; }
        
        public int getRetentionDays() { return retentionDays; }
        public void setRetentionDays(int retentionDays) { this.retentionDays = retentionDays; }
        
        public boolean isLogFailures() { return logFailures; }
        public void setLogFailures(boolean logFailures) { this.logFailures = logFailures; }
        
        public boolean isAutoCleanup() { return autoCleanup; }
        public void setAutoCleanup(boolean autoCleanup) { this.autoCleanup = autoCleanup; }
    }
    
    // Main class getters and setters
    public boolean isEnabled() { return enabled; }
    public void setEnabled(boolean enabled) { this.enabled = enabled; }
    
    public String getDefaultProvider() { return defaultProvider; }
    public void setDefaultProvider(String defaultProvider) { this.defaultProvider = defaultProvider; }
    
    public String getFallbackProvider() { return fallbackProvider; }
    public void setFallbackProvider(String fallbackProvider) { this.fallbackProvider = fallbackProvider; }
    
    public boolean isEnableFailover() { return enableFailover; }
    public void setEnableFailover(boolean enableFailover) { this.enableFailover = enableFailover; }
    
    public AliyunConfig getAliyun() { return aliyun; }
    public void setAliyun(AliyunConfig aliyun) { this.aliyun = aliyun; }
    
    public TencentConfig getTencent() { return tencent; }
    public void setTencent(TencentConfig tencent) { this.tencent = tencent; }
    
    public HuaweiConfig getHuawei() { return huawei; }
    public void setHuawei(HuaweiConfig huawei) { this.huawei = huawei; }
    
    public VerificationConfig getVerification() { return verification; }
    public void setVerification(VerificationConfig verification) { this.verification = verification; }
    
    public RateLimitConfig getRateLimit() { return rateLimit; }
    public void setRateLimit(RateLimitConfig rateLimit) { this.rateLimit = rateLimit; }
    
    public TemplateConfig getTemplate() { return template; }
    public void setTemplate(TemplateConfig template) { this.template = template; }
    
    public RecordConfig getRecord() { return record; }
    public void setRecord(RecordConfig record) { this.record = record; }
}
